
'use strict';
goog.provide('Blockly.Arduino.Inout');

goog.require('Blockly.Arduino');



Blockly.Arduino.inout_highlow = function() {
  var dropdown_d_value = this.getFieldValue('text_values');
  // TODO: Assemble JavaScript into code variable.
  var code = dropdown_d_value;
  // TODO: Change ORDER_NONE to the correct strength.
  return [code, Blockly.Arduino.ORDER_ATOMIC];
};




Blockly.Arduino.inout_digital_pin = function() {
  var dropdown_d_value = this.getFieldValue('d_pin_values');
  // TODO: Assemble JavaScript into code variable.
  var code = dropdown_d_value;
  // TODO: Change ORDER_NONE to the correct strength.
  return [code, Blockly.Arduino.ORDER_ATOMIC];
};


Blockly.Arduino.inout_analog_pin = function() {
  var dropdown_d_value = this.getFieldValue('a_pin_values');
  // TODO: Assemble JavaScript into code variable.
  var code = dropdown_d_value;
  // TODO: Change ORDER_NONE to the correct strength.
  return [code, Blockly.Arduino.ORDER_ATOMIC];
};

Blockly.Arduino['inout_digital_write'] = function() {
  var value_pin = Blockly.Arduino.valueToCode(this, 'pin', Blockly.Arduino.ORDER_ATOMIC);
  var value_p_value = Blockly.Arduino.valueToCode(this, 'p_value', Blockly.Arduino.ORDER_ATOMIC);
  // TODO: Assemble JavaScript into code variable.
  Blockly.Arduino.setups_['setup_output_' + value_pin] = 'pinMode(' + value_pin + ', OUTPUT);';
  var code = 'digitalWrite(' + value_pin + ', ' + value_p_value + ');\n';
  return code;
};


Blockly.Arduino['inout_digital_read'] = function() {
  var value_pin = Blockly.Arduino.valueToCode(this, 'pin', Blockly.Arduino.ORDER_ATOMIC);
  // TODO: Assemble JavaScript into code variable.
  Blockly.Arduino.setups_['setup_output_' + value_pin] = 'pinMode(' + value_pin + ', INPUT);';
  var code = 'digitalRead(' + value_pin + ')';
  // TODO: Change ORDER_NONE to the correct strength.
  return [code, Blockly.Arduino.ORDER_NONE];
};

Blockly.Arduino['inout_analog_write'] = function() {
  var value_pin = Blockly.Arduino.valueToCode(this, 'pin', Blockly.Arduino.ORDER_ATOMIC);
  var value_p_value = Blockly.Arduino.valueToCode(this, 'p_value', Blockly.Arduino.ORDER_ATOMIC);
  // TODO: Assemble JavaScript into code variable.
  Blockly.Arduino.setups_['setup_output_' + value_pin] = 'pinMode(' + value_pin + ', OUTPUT);';
  var code = 'analogWrite(' + value_pin + ', ' + value_p_value + ');\n';
  return code;
};


Blockly.Arduino['inout_analog_read'] = function() {
  var value_pin = Blockly.Arduino.valueToCode(this, 'pin', Blockly.Arduino.ORDER_ATOMIC);
  // TODO: Assemble JavaScript into code variable.
  Blockly.Arduino.setups_['setup_output_' + value_pin] = 'pinMode(' + value_pin + ', INPUT);';
  var code = 'analogRead(' + value_pin + ')';
  // TODO: Change ORDER_NONE to the correct strength.
  return [code, Blockly.Arduino.ORDER_NONE];
};
